//
//  String+Extensions.swift
//  正则表达式
//
//  Created by tuimao on 2017/8/14.
//  Copyright © 2017年 tuimao. All rights reserved.
//

import UIKit

extension String {
    
    func cz_href()->(link:String, text:String)?{
        //匹配方案
        let pattern = "<a href=\"(.*?)\".*?>(.*?)</a>"
        //创建正则表达式，并匹配第一项
         guard let regx = try? NSRegularExpression(pattern: pattern, options: []),
            let result = regx.firstMatch(in: self, options: [], range: NSRange(location: 0, length: characters.count)) else{
                return nil
        }
        // 获取结果
        let link = (self as NSString).substring(with: result.rangeAt(1))
        let text = (self as NSString).substring(with: result.rangeAt(2))
        return (link,text)
    }
}
